<template>
  <div class="messagecard" style="height: 220px;">
    <el-card class="messagecard">
      <el-tabs
        v-model="activeName"
        @tab-click="handleTabsClick"
      >
        <el-tab-pane :label="tabLabel" name="first" v-loading="loading">
          <div v-if="!dataList.length " class="nodata">
            <el-image style="width: 62px; height: 62px" :src="require('@/assets/images/empty__image@2x.png')" />
            <p style="padding: 0; margin: 0; font-size: 12px;color:#C0C4CC;margin-top:8px;">暂无新消息</p>
          </div>
          <div v-else>
            <div v-for="(item,index) in dataList " :key="index" class="messagebox" @click="getDetail(item)">
              <div class="me-left">
                <span class="dot">`</span>
                <span class="messagetitle">{{ item.noticeTitle }}</span>
              </div>
              <div class="item-time">{{ parseTime(item.createTime, '{y}-{m}-{d}') }}</div>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane :label="tabLabel2" name="second" v-loading="loading2">
          <div v-if="!dataList2.length " class="nodata">
            <el-image style="width: 62px; height: 62px" :src="require('@/assets/images/empty__image@2x.png')" />
            <p style=" padding: 0; margin: 0; font-size: 12px;color:#C0C4CC;margin-top:8px;">暂无新消息</p>
          </div>
          <div v-else>
            <div v-for="(item,index) in dataList2" :key="index" class="messagebox" @click="getDetail(item)">
              <div class="me-left">
                <span class="dot">`</span>
                <span class="messagetitle">{{ item.noticeTitle }}</span>
              </div>
              <div class="item-time">{{ parseTime(item.createTime, '{y}-{m}-{d}') }}</div>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-card>
    <el-dialog title="详情" :visible.sync="open" width="780px" append-to-body class="message-detail">
      <div>
        <div class="message-body">
          <div class="title">{{ form.noticeTitle }}</div>
          <div class="des">
            <div class="level">{{ form.noticeType === '1'?'通知': '公告' }}</div>
            <div class="flex-1" />
            <div class="date">发布时间：{{ parseTime(form.createTime, '{y}-{m}-{d}') }}</div>
          </div>
          <div class="content ql-editor" v-html="form.noticeContent"></div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script >
import { allList, getNotice } from "@/api/system/notice";
export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      loading2: true,
      activeName: 'first',
      dataList: [],
      dataList2: [],
      tabLabel: '通知（0）',
      tabLabel2: '公告（0）',
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    getDetail(item) {
      getNotice(item.noticeId).then(response => {
        this.form = response.data;
        this.open = true;
      });
    },
    handleTabsClick(tab, event) {
      if (this.activeName == 'first') {
        this.dataList = []
        this.getNotice()
      } else if(this.activeName == 'second'){
        this.dataList2 = []
        this.getNotice2()
      }
    },
    getList() {
      this.getNotice()
      this.getNotice2()
    },
    getNotice() {
      this.loading = true;
      allList({noticeType: 1}).then(response => {
        this.dataList = response.data
        this.tabLabel = '通知（' + response.data.length + '）'
      }).catch((e) => {
        this.tabLabel = '通知（0）'
      }).finally(() => {
        this.loading = false;
      });
    },
    getNotice2() {
      this.loading2 = true;
      allList({noticeType: 2}).then(response => {
        this.dataList2 = response.data
        this.tabLabel2 = '公告（' + response.data.length + '）'
      }).catch((e) => {
        this.tabLabel2 = '公告（0）'
      }).finally(() => {
        this.loading2 = false;
      });
    }
  }
}
</script>
<style lang="scss" scoped>
  .messagecard {
    width: 100%;
    height: 100%;
    background: #fff;
    .el-card__body{
      height: 100% !important;
      display: flex;
      flex-direction: column;
      overflow: hidden!important;
      .el-tabs{
        height: calc(100% - 0px);
        .el-tabs__content{
          height: 100%;
          overflow: hidden;
          .el-tab-pane{
            height: 120px;
            overflow-y: auto;
          }
        }
      }
    }
    .el-tabs{
      flex: 1;
      display: flex;
      flex-direction: column;
    }
    .nodata{
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    .messagebox{
      margin: 0 0 20px;
      display: flex;
      align-items: center;
      cursor: pointer;
      .me-left{
        flex: 1;
        display: flex;
        align-items: center;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        margin-right: 20px;
        font-size: 14px;
      }
      .item-time{
        width: 145px;
        font-size: 14px;
        font-weight: 300;
        color: #909399;
      }
    }
    .dot {
      color: #F56C6C;
      width:5px;
      height: 5px;
      background: #F56C6C;
      border-radius: 50%;
      margin-right: 10px;
      text-align: center;
    }
    .messagetitle{
      min-width: 400px;
      width: 400px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      color: #606266;
    }
  }
  ::v-deep .el-tabs__nav-wrap::after{
    height: 1px;
  }
  .message-detail{
    .message-body{
      display: flex;
      flex-direction: column;
      min-height: 490px;
      .title{
        text-align: center;
        // margin-top: 24px;
        margin-bottom: 8px;
        font-size: 18px;
        font-family: HarmonyOS Sans SC-Medium, HarmonyOS Sans SC;
        font-weight: 500;
        color: #131314;
        line-height: 24px;
      }
      .des{
        display: flex;
        line-height: 24px;
        border-bottom: 1px solid #D8D8D8;
        font-size: 12px;
         color: #606266;
         padding-bottom: 4px;
         margin-bottom: 24px;
        .date{
          margin-left: auto;
        }
      }
    }
  }
</style>
<style >
 .messagecard  .el-card__body{
    height: 100% !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
 }

</style>
